//
//  WorkmateEntryInsurance.m
//  MyProject
//
//  Created by 石小强 on 2018/4/15.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "WorkmateEntryInsurance.h"

@implementation WorkmateEntryInsurance

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initSubViewsWithFrame:frame];
    }
    return self;
}

- (void)initSubViewsWithFrame:(CGRect)frame {
    CGFloat ItemW = frame.size.width;
    
    UILabel *topLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 25, ItemW, 16)];
    topLabel.textAlignment = NSTextAlignmentCenter;
//    NSString *topText = @"";
//    NSMutableAttributedString *topAttrText = [[NSMutableAttributedString alloc] initWithString:topText];
//    [topAttrText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:16] range:NSMakeRange(0, 9)];
//    [topAttrText addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x48565A) range:NSMakeRange(0, 5)];
//    [topAttrText addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x00BCCC) range:NSMakeRange(5, 4)];
//    topLabel.attributedText = topAttrText;
    topLabel.font = [UIFont fontWithName:@"PingFang SC" size:16];
    self.topLabel = topLabel;
    [self addSubview:topLabel];
    
    UILabel *centerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(topLabel.frame) + 26, ItemW, 11)];
    centerLabel.textAlignment = NSTextAlignmentCenter;
    centerLabel.text = @"";
    centerLabel.font = [UIFont fontWithName:@"PingFang SC" size:14];
    centerLabel.textColor = UIColorFromRGB(0x859BA6);
    self.centerLabel = centerLabel;
    [self addSubview:centerLabel];
    
    CGSize bottomLabelSize = [Tool sizeWithText:@"共0条评价" font:[UIFont systemFontOfSize:11]];
    
    _starView = [[HCSStarRatingView alloc] initWithFrame:CGRectMake((frame.size.width - 100 - 9 - bottomLabelSize.width) * 0.5, CGRectGetMaxY(centerLabel.frame) + 26, 100, 15)];
    _starView.emptyStarColor = UIColorFromRGB(0xBFBFBF);
    _starView.emptyStarImage = [UIImage imageNamed:@"ic_stars_没选中没选中Unselected"];
    _starView.filledStarImage = [UIImage imageNamed:@"ic_stears_Selected"];
    _starView.halfStarImage = [UIImage imageNamed:@"ic_stars_Halfselected"];
    _starView.maximumValue = 5;
    _starView.minimumValue = 0;
    _starView.value = 2.5;
    _starView.allowsHalfStars = YES;
    _starView.accurateHalfStars = YES;
    _starView.continuous = YES;
    [self addSubview:_starView];
    [_starView addTarget:self action:@selector(starViewValueChanged:) forControlEvents:UIControlEventValueChanged];
    
    _bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_starView.frame) + 9, _starView.mj_y, 100, 15)];
    _bottomLabel.text = @"共0条评价";
    _bottomLabel.font = [UIFont systemFontOfSize:11];
    _bottomLabel.textColor = UIColorFromRGB(0xC0C8CC);
    [self addSubview:_bottomLabel];
    
    _topBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
    [self addSubview:_topBtn];
}

- (void)starViewValueChanged:(HCSStarRatingView *)starView {
    self.starView.value = [self.model.star floatValue];
}

- (void)setModel:(AssurePassModel *)model {
    _model = model;
    
    NSString *jobName = [NSString stringWithFormat:@"保过职位：%@", model.jobName];;
    NSMutableAttributedString *topAttrText = [[NSMutableAttributedString alloc] initWithString:jobName];
    [topAttrText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang SC" size:16] range:NSMakeRange(0, jobName.length)];
    [topAttrText addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x48565A) range:NSMakeRange(0, 5)];
    [topAttrText addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x00BCCC) range:NSMakeRange(5, jobName.length - 5)];
    self.topLabel.attributedText = topAttrText;
    
//    self.topLabel.text = [NSString stringWithFormat:@"保过职位：%@", model.jobName];
    self.centerLabel.text = [NSString stringWithFormat:@"￥%@", model.price];
    self.starView.value = [model.star floatValue];
    self.bottomLabel.text = [NSString stringWithFormat:@"共%@条评价", model.evaluateCount];
}

@end
